<template>
    <view class="content" v-if="isShow">
        <view class="bg"></view>
        
        <view class="title">
            <image src="../../static/icon/order.png" class="top-icon"></image>
            <view class="u-flex-1">
                运输路线：<text class="dest">{{data.line}}</text>
            </view>
        </view>
        
        <view class="box">
            <view class="route">
                <image src="../../static/icon/line.png" class="line"></image>
                <view class="route-r">
                    
                    <view>
                        <view>始发地</view>
                        <view class="address">{{data.origin}}</view>
                    </view>
                    <view class="u-p-t-50">
                        <view>目的地</view>
                        <view class="address">{{data.destination}}</view>
                    </view>
                </view>
            </view>
            <view class="item">
                <view class="grey">装车地点</view>
                <view class="item-right">{{data.loading_site}}</view>
            </view>
            <view class="item" v-if="data.start_date">
                <view class="grey">发车日期</view>
                <view class="item-right">{{data.start_date}}</view>
            </view>
			<view class="item" v-if="data.start_time">
			    <view class="grey">发车时间</view>
			    <view class="item-right">{{data.start_time}}</view>
			</view>
            <view class="item" v-if="role==2">
                <view class="grey">车辆类型</view>
                <view class="item-right">{{data.vehicle}}</view>
            </view>
            <view class="item" v-if="role==2">
                <view class="grey">车长</view>
                <view class="item-right">{{data.length}}米</view>
            </view>
        </view>
        
        <view class="box">
            <view class="work-title">收货方</view>
            <view class="item">
                <view class="grey">收货地址</view>
                <view class="item-right">{{data.address}}</view>
            </view>
            <view class="item">
                <view class="grey">经营位置</view>
                <view class="item-right">{{data.position}}</view>
            </view>
            <view class="item">
                <view class="grey">联系人</view>
                <view class="item-right">{{data.recipient_contact}}</view>
            </view>
            <view class="item">
                <view class="grey">联系方式</view>
                <view class="item-right">{{data.recipient_phone}}</view>
            </view>
        </view>
        
        <view class="box">
            <view class="work-title">发货方</view>
            <view class="item">
                <view class="grey">发货方</view>
                <view class="item-right">{{data.shipper}}</view>
            </view>
            <view class="item">
                <view class="grey">联系人</view>
                <view class="item-right">{{data.shipper_contact}}</view>
            </view>
            <view class="item">
                <view class="grey">联系方式</view>
                <view class="item-right">{{data.shipper_phone}}</view>
            </view>
            <view class="item" v-if="data.remark">
                <view class="grey">地址备注</view>
                <view class="item-right">{{data.remark}}</view>
            </view>
            <view class="item" v-if="data.image">
                <view class="grey">上传图片</view>
                <view class="item-right" style="position: relative;">
                    <image v-if="data.image" :src="data.image" class="up"></image>
                    <view v-if="data.image" @click.stop="previewImage()" 
						style="position: absolute;bottom: 0;width: 180rpx;right: 0;text-align: center;background:rgba(0, 0, 0, 0.4);color: #fff;">查看</view>
                </view>
            </view>
        </view>
        
        <view class="list-title">发货明细</view>
        <view class="box" v-for="(item, index) in data.goods" :key="index">
            <view class="item">
                <view class="grey">货物类型</view>
                <view class="item-right">{{item.type}}</view>
            </view>
            <view class="item">
                <view class="grey">产品名称</view>
                <view class="item-right">{{item.goods}}</view>
            </view>
            
            <view class="item" v-if="role==1 && item.brand">
                <view class="grey">品牌</view>
                <view class="item-right">{{item.brand}}件</view>
            </view>
            <view class="item" v-if="role==1 && item.packages">
                <view class="grey">包装</view>
                <view class="item-right">{{item.packages}}件</view>
            </view>
            <view class="item" v-if="role==1 && item.model">
                <view class="grey">型号</view>
                <view class="item-right">{{item.model}}件</view>
            </view>
            
            <view class="item">
                <view class="grey">件数</view>
                <view class="item-right">{{item.num}}件</view>
            </view>
            
            <view class="item" v-if="role==1">
                <view class="grey">预估重量</view>
                <view class="item-right">{{item.estimate_weight}}斤(500g/斤)</view>
            </view>
            
            <view class="price" v-if="role==1">
                
                <view v-if="item.freight_type ==1">预估运费 <text class="price-num">{{item.freight*item.num || '自动计算'}}</text>元</view>
                <view v-if="item.freight_type ==2">预估运费 <text class="price-num">{{item.estimate_freight || '自动计算'}}</text>元</view>
            	<view v-if="item.freight_type == 3">预估运费 <text class="price-num">0</text>元</view>
                <view class="tip" v-if="item.freight_type == 3">提示: 您的产品体积不确定，以现场发货管理员确认为准</view>
            </view>
            
        </view>
        
        <view class="box">
            <view class="item">
                <view class="grey">总件数</view>
                <view class="item-right">{{data.num}}件</view>
            </view>
            <view class="item">
                <view class="grey">预估总重量</view>
                <view class="item-right">{{data.weight}}斤(500g/斤)</view>
            </view>
            <view class="item" v-if="data.start_date || data.loading_time">
                <view class="grey">预计装货时间</view>
                <view class="item-right">{{ data.start_date + ' ' + data.loading_time}}</view>
            </view>
            <view class="item" v-if="data.goods_remark">
                <view class="grey">货物备注</view>
                <view class="item-right">{{data.goods_remark}}</view>
            </view>
            <view class="item" v-if="data.carriage">
                <view class="grey">车厢位置</view>
                <view class="item-right">{{data.carriage}}</view>
            </view>
        </view>
        
        <view class="box">
            <view class="item">
                <view class="grey">运费</view>
                <view class="item-right">￥{{data.freight}}</view>
            </view>
            <view class="item" @click="show = true">
                <view class="grey">运费结算</view>
                <view class="item-right" style="font-weight: 400;">
                    <text style="color: grey;font-size: 28rpx;" v-if="!freightJs.label">请选择</text>
                    <text style="font-size: 28rpx;" v-else>{{freightJs.label}}</text>
                    <u-icon name="arrow-right" color="#979797" size="28" class="u-m-l-5 u-padding-left-5"></u-icon>
                </view>
            </view>
            <view class="item" v-if="data.authority_zero==1&&freightJs.value==1" style="align-items: center;">
                <view class="grey">抹零</view>
                <view class="item-right u-flex" style="font-weight: 400;">
                   
                    <!-- <input type="number" v-model="countZero" placeholder="请输入" class="inp"  @oninput="oninput"> -->
                    <u-input v-model="countZero" type="digit" input-align="right" class="inp" max="10" placeholder="请输入" @input = "oninput" />
                    
                    <text class="u-padding-left-5">元</text>
                </view>
            </view>
            
             <!-- v-if="data.goods_remark&&freightJs.value==1" -->
            <view class="item" v-if="freightJs.value==1">
                <view class="grey">运费</view>
                <view class="item-right u-flex" style="font-weight: 400;">
                    <input type="digit" v-model="freight" placeholder="" class="inp" >
                    <text class="u-padding-left-5">元</text>
                </view>
            </view>
            
        </view>
        
        
        
        
        <view class="footer">
            <view class="f-top">您本次线上下单预计优惠{{ countZero||'0' }}元</view>
            <view class="f-down">
                <view>
                    <view>
                        实收运费
                        <text class="f-price">￥<text class="f-price-num">{{ freight }}</text></text>
                    </view>
                    <view class="f-tip">
                        阅读并同意<text class="f-tip-t" @click="showPrivacy = true">《电子运单契约条款及隐私政策》</text>
                    </view>
                </view>
                <view class="f-btn" @click="$noMultipleClicks(doSubmit)">提交订单</view>
            </view>
        </view>
        
        
        <template v-if="show">
        	<u-select v-model="show" mode="single-column" :list="showList" @confirm="confirm"></u-select>
        </template>
        
		<!-- 电子运单契约条款及隐私政策 -->
		<u-popup v-model="showPrivacy" :round="true" mode="bottom" :closeable="true" width="750rpx" height="1000rpx" border-radius="14">
		    <view class="pop-box-cou">
		        <view class="pop-title">电子运单契约条款及隐私政策</view>
		        <view>
		            <scroll-view :scroll-y="true" style="height: 800rpx;">
		                <view>
		                    <u-parse :html="content"></u-parse>
		                </view>
		            </scroll-view>
		        </view>
		    </view>
		</u-popup>
    </view>
</template>

<script>
    export default {
        data() {
            return {
				noClick: true,//连点
				showPrivacy: false,//电子运单契约条款及隐私政策
				isShow: false,
				data: {},
				content: '',//规则
				freight: 0,//运费
				order_id: '',
                show:'',//结算 选项
                showList:[{
                    label:'已结算',
                    value:1
                },
                {
                    label:'未结算',
                    value:2
                }],
                countZero:'',//抹零
                freightJs:{},
                role:''
            };
        },
        onLoad(option) {
            
			if (option.order_id) {
				this.order_id = option.order_id
				this.getData()
			}
            if(option.role){
                this.role = option.role
            }
            
            if(option.role==1){
                this.title = '零担订单明细确认'
            }else{
                this.title = '包车订单明细确认'
            }
            uni.setNavigationBarTitle({
                title: this.title
            });
            
            
			this.getRule()
        },
        methods: {
            previewImage(){
                let url = []
                
                url[0]= this.data.image
                uni.previewImage({
                    urls:url,
                    longPressActions: {
                        success: function(data) {
                        },
                        fail: function(err) {
                            console.log(err.errMsg);
                        }
                    }
                });
            },
            oninput(e){
                this.freight = Number(this.data.freight)-Number(this.countZero)
            },
            confirm(e){
				this.freight = this.data.freight
				this.countZero = ''
                this.freightJs = e[0]
            },
			// 提交订单
            doSubmit() {
                
                if(!this.freightJs.label){
                    this.$toast('请选择运费结算');
                    return
                }
                
				if(this.freightJs.value==1&&this.data.authority_zero==1){
                    if(!this.countZero){
                        this.$toast('请输入抹零金额');
                        return
                    }
                }
                
                console.log({
				    user_token: this.$getSync('token'),
					order_id: this.order_id,//订单id
					pay_status: this.freightJs.value==1?2:1,//发货端结算状态 1未结算 2已结算
					zero_amount: this.countZero,//发货端抹零金额 已结算可添加
					amount: this.freight,//发货端运费 已结算可添加
				})
                
				this.$ajax('insert_order_third', {
				    user_token: this.$getSync('token'),
					order_id: this.order_id,//订单id
					pay_status: this.freightJs.value==1?2:1,//发货端结算状态 1未结算 2已结算
					zero_amount: this.countZero,//发货端抹零金额 已结算可添加
					amount: this.freight,//发货端运费 已结算可添加
				}).then(ret => {
				    if (ret.success == 1000) {
						let data = ret.detail
                        let _this = this
                        this.$alert(ret.msg,function(){
							uni.reLaunch({
								url: `/pages/tabbar/index`
							});
                        });
                        
                        // if(this.freightJs.value==1){
                        //     let _this = this
                            
                            
                        // }else{
                        //     this.$gTo(`/pages/pay/pay?order_id=${data.order_id}&money=${data.order_amount}&balance=${data.balance}`)
                        // }
				    } else {
				        this.$toast(ret.msg);
				    }
				});
            },
			
			// 获取订单详情
			getData() {
			    this.$ajax('orders_detail', {
			        user_token: this.$getSync('token'),
					order_id: this.order_id,//订单id
			    }).then(ret => {
			        if (ret.success == 1000) {
						this.data = ret.detail
                        this.freight = this.data.freight
						this.isShow = true
			        } else {
			            this.$toast(ret.msg);
			        }
			    });
			},
			
			// 获取电子运单契约条款及隐私政策
			getRule() {
			    this.$ajax('select_rules', {
			        user_token: this.$getSync('token'),
					type: 2,//1计算规则 2电子运单契约条款及隐私政策 3充值条款
			    }).then(ret => {
			        this.content = ret.detail.rules
			    });
			},
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f2f4fa;
    }
    .up{
    	width: 180rpx;
    	height: 180rpx;
    }
    .content {
    	padding: 30rpx 20rpx 90px;
    }
    .bg {
    	width: 100%;
    	height: 600rpx;
    	position: absolute;
    	top: 0;
    	left: 0;
    	// z-index: -1;
        background: linear-gradient(to bottom, #004580,#18568c, #f2f4fa);
    }
    .title{
        padding: 10rpx 0 40rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 36rpx;
        color: #fff;
        
        position: relative;
        // z-index: 999;
    }
    .top-icon{
        width: 69rpx;
        height: 69rpx;
        margin-right: 20rpx;
    }
    .dest{
        font-weight: bold;
    }
    
    .box{
        padding: 20rpx 30rpx;
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 16rpx;
        position: relative;
        // z-index: 999;
    }
    .route{
        padding: 10rpx 0 20rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .line{
        width: 31rpx;
        height: 162rpx;
        margin-right: 15rpx;
    }
    .route-r{
        flex: 1;
        font-size: 34rpx;
        font-weight: bold;
    }
    .address{
        font-size: 28rpx;
        color: #999999;
        font-weight: normal;
    }
    
    .work-title{
        font-size: 32rpx;
        font-weight: bold;
        padding-top: 10rpx;
        padding-bottom: 15
        px;
    }
    .item{
        padding: 15rpx 0;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }
    .item-right{
        flex: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-left: 20rpx;
        text-align: right;
    }
    .grey{
        color: #656565;
    }
    .list-title{
        font-size: 34rpx;
        color: #fff;
        background: linear-gradient(to right, #7fb1e4, #c7e1f9);
        border-radius: 20rpx;
        padding: 15rpx 30rpx;
        height: 120rpx;
        margin-bottom: -40rpx;
    }
    .price{
        padding: 25rpx 0 10rpx;
        border-top: 2rpx solid #f4f4f4;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        font-size: 28rpx;
    }
    .price-num{
        font-size: 40rpx;
        font-weight: bold;
        padding-left: 10rpx;
        padding-right: 5rpx;
    }
    
    .pt-box{
        padding: 35rpx 30rpx;
        background-color: #fff;
        border-radius: 20rpx;
        margin-bottom: 16rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .icon-02{
        width: 55rpx;
        height: 55rpx;
        margin-right: 15rpx;
    }
    .pt-t1{
        font-size: 32rpx;
        font-weight: bold;
        padding-right: 20rpx;
    }
    .pt-t2{
        font-size: 22rpx;
        color: #929292;
    }
    .pt-t3{
        font-size: 22rpx;
        color: #ff5f2b;
    }
    
    .l-icon{
        width: 30rpx;
        height: 30rpx;
        background-color: #ff4926;
        border-radius: 10rpx;
        font-size: 20rpx;
        color: #fff;
        text-align: center;
        line-height: 30rpx;
        margin-right: 10rpx;
    }
    .item-right2{
        flex: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-left: 15rpx;
    }
    .inp{
        flex: 1;
        text-align: right;
    }
    .tip{
        color: #fe6a00;
        font-weight: normal;
    }
    
    
    .footer{
        width: 750rpx;
        height: 170rpx;
        background-color: #fff;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 9;
    }
    .f-top{
        height: 50rpx;
        background-color: #ddebfa;
        font-size: 25rpx;
        color: #0c89ea;
        line-height: 50rpx;
        text-align: right;
        padding-right: 35rpx;
    }
    .f-down{
        padding: 15rpx 20rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .f-price{
        color: #ff3f00;
        padding-left: 15rpx;
    }
    .f-price-num{
        font-size: 38rpx;
        font-weight: bold;
    }
    .f-tip{
        font-size: 22rpx;
        color: #656565;
        padding-top: 5rpx;
    }
    .f-tip-t{
        color: #000;
    }
    .f-btn{
        font-size: 28rpx;
        color: #fff;
        padding: 15rpx 35rpx;
        background-color: #00457f;
        border-radius: 50rpx;
    }
    
    
    // 优惠券
    .pop-box-cou{
        padding: 0 30rpx;
    }
    .pop-title{
        font-size: 34rpx;
        font-weight: bold;
        text-align: center;
        padding: 30rpx;
    }
    .pop-item{
        position: relative;
        margin-bottom: 20rpx;
    }
    .cou-bg{
        width: 694rpx;
        height: 176rpx;
    }
    .item-cou{
        width: 670rpx;
        height: 165rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: absolute;
        left: 10rpx;
        top: 0;
    }
    .item-cou-l{
		width: 180rpx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        color: #ff602c;
    }
    .cou-num{
        font-size: 44rpx;
        font-weight: bold;
    }
    .item-cou-r{
        padding-left: 30rpx;
        padding-right: 15rpx;
        flex: 1;
    }
    .cou-time{
        font-size: 24rpx;
        color: #8b8b8b;
    }
    .pop-cou-none{
        font-size: 30rpx;
        color: #9b9b9b;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding-top: 100rpx;
    }
    .price-04{
        width: 92rpx;
        height: 79rpx;
        margin-bottom: 20rpx;
    }
    

</style>
